package f;

import f.f0.f.c;
import f.f0.f.d;
import f.f0.j.f;
import java.lang.ref.Reference;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* compiled from: ConnectionPool */
public final class g {
    public static final Executor g;
    public final int a = 5;
    public final long b;
    public final Runnable c = new a();
    public final Deque<c> d = new ArrayDeque();
    public final d e = new d();
    public boolean f;

    /* compiled from: ConnectionPool */
    public class a implements Runnable {
        /* JADX WARNING: Missing exception handler attribute for start block: B:40:0x007b */
        /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
        public void run() {
            /*
            r14 = this;
        L_0x0000:
            r0 = f.g.this;
            r1 = java.lang.System.nanoTime();
            monitor-enter(r0);
            r3 = r0.d;	 Catch:{ all -> 0x007f }
            r3 = r3.iterator();	 Catch:{ all -> 0x007f }
            r4 = 0;
            r5 = -9223372036854775808;
            r7 = 0;
            r8 = 0;
            r9 = 0;
        L_0x0013:
            r10 = r3.hasNext();	 Catch:{ all -> 0x007f }
            if (r10 == 0) goto L_0x0035;
        L_0x0019:
            r10 = r3.next();	 Catch:{ all -> 0x007f }
            r10 = (f.f0.f.c) r10;	 Catch:{ all -> 0x007f }
            r11 = r0.a(r10, r1);	 Catch:{ all -> 0x007f }
            if (r11 <= 0) goto L_0x0028;
        L_0x0025:
            r9 = r9 + 1;
            goto L_0x0013;
        L_0x0028:
            r8 = r8 + 1;
            r11 = r10.o;	 Catch:{ all -> 0x007f }
            r11 = r1 - r11;
            r13 = (r11 > r5 ? 1 : (r11 == r5 ? 0 : -1));
            if (r13 <= 0) goto L_0x0013;
        L_0x0032:
            r4 = r10;
            r5 = r11;
            goto L_0x0013;
        L_0x0035:
            r1 = r0.b;	 Catch:{ all -> 0x007f }
            r10 = -1;
            r12 = 0;
            r3 = (r5 > r1 ? 1 : (r5 == r1 ? 0 : -1));
            if (r3 >= 0) goto L_0x0052;
        L_0x003f:
            r3 = r0.a;	 Catch:{ all -> 0x007f }
            if (r8 <= r3) goto L_0x0044;
        L_0x0043:
            goto L_0x0052;
        L_0x0044:
            if (r8 <= 0) goto L_0x0049;
        L_0x0046:
            r1 = r1 - r5;
            monitor-exit(r0);	 Catch:{ all -> 0x007f }
            goto L_0x005e;
        L_0x0049:
            if (r9 <= 0) goto L_0x004d;
        L_0x004b:
            monitor-exit(r0);	 Catch:{ all -> 0x007f }
            goto L_0x005e;
        L_0x004d:
            r0.f = r7;	 Catch:{ all -> 0x007f }
            monitor-exit(r0);	 Catch:{ all -> 0x007f }
            r1 = r10;
            goto L_0x005e;
        L_0x0052:
            r1 = r0.d;	 Catch:{ all -> 0x007f }
            r1.remove(r4);	 Catch:{ all -> 0x007f }
            monitor-exit(r0);	 Catch:{ all -> 0x007f }
            r0 = r4.e;
            f.f0.c.g(r0);
            r1 = r12;
        L_0x005e:
            r0 = (r1 > r10 ? 1 : (r1 == r10 ? 0 : -1));
            if (r0 != 0) goto L_0x0063;
        L_0x0062:
            return;
        L_0x0063:
            r0 = (r1 > r12 ? 1 : (r1 == r12 ? 0 : -1));
            if (r0 <= 0) goto L_0x0000;
        L_0x0067:
            r3 = 1000000; // 0xf4240 float:1.401298E-39 double:4.940656E-318;
            r5 = r1 / r3;
            r3 = r3 * r5;
            r1 = r1 - r3;
            r0 = f.g.this;
            monitor-enter(r0);
            r3 = f.g.this;	 Catch:{ InterruptedException -> 0x007b }
            r2 = (int) r1;	 Catch:{ InterruptedException -> 0x007b }
            r3.wait(r5, r2);	 Catch:{ InterruptedException -> 0x007b }
            goto L_0x007b;
        L_0x0079:
            r1 = move-exception;
            goto L_0x007d;
        L_0x007b:
            monitor-exit(r0);	 Catch:{ all -> 0x0079 }
            goto L_0x0000;
        L_0x007d:
            monitor-exit(r0);	 Catch:{ all -> 0x0079 }
            throw r1;
        L_0x007f:
            r1 = move-exception;
            monitor-exit(r0);	 Catch:{ all -> 0x007f }
            throw r1;
            */
            throw new UnsupportedOperationException("Method not decompiled: f.g$a.run():void");
        }
    }

    static {
        TimeUnit timeUnit = TimeUnit.SECONDS;
        SynchronousQueue synchronousQueue = new SynchronousQueue();
        byte[] bArr = f.f0.c.a;
        g = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, timeUnit, synchronousQueue, new f.f0.d("OkHttp ConnectionPool", true));
    }

    public g() {
        TimeUnit timeUnit = TimeUnit.MINUTES;
        this.b = timeUnit.toNanos(5);
    }

    public final int a(c cVar, long j) {
        List list = cVar.n;
        int i = 0;
        while (i < list.size()) {
            Reference reference = (Reference) list.get(i);
            if (reference.get() != null) {
                i++;
            } else {
                f.f0.f.g.a aVar = (f.f0.f.g.a) reference;
                StringBuilder g = c.b.a.a.a.g("A connection to ");
                g.append(cVar.c.a.a);
                g.append(" was leaked. Did you forget to close a response body?");
                f.a.m(g.toString(), aVar.a);
                list.remove(i);
                cVar.k = true;
                if (list.isEmpty()) {
                    cVar.o = j - this.b;
                    return 0;
                }
            }
        }
        return list.size();
    }
}
